home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / boolean.c < prev    next >
C/C++ Source or Header  |  1993-06-07  |  7KB  |  246 lines

  1.  
  2.        /*********************************************
  3.        *
  4.        *   file d:\cips\boolean.c
  5.        *
  6.        *   Functions: This file contains
  7.        *      main
  8.        *
  9.        *   Purpose:
  10.        *      This file contains the main calling
  11.        *      routine that calls the Boolean operations.
  12.        *
  13.        *   External Calls:
  14.        *      gin.c - get_image_name
  15.        *      numcvrt.c - get_integer
  16.        *                  int_convert
  17.        *      tiff.c - read_tiff_header
  18.        *      boole.c - and_image
  19.        *                or_image
  20.        *                xor_image
  21.        *                nand_image
  22.        *                nor_image
  23.        *                not_image
  24.        *
  25.        *   Modifications:
  26.        *      3 March 1993 - created
  27.        *
  28.        ***********************************************/
  29.  
  30. #include "cips.h"
  31.  
  32.  
  33.  
  34. short the_image[ROWS][COLS];
  35. short out_image[ROWS][COLS];
  36.  
  37. main(argc, argv)
  38.    int argc;
  39.    char *argv[];
  40. {
  41.  
  42.    char     name[80], name2[80], name3[80], type[80];
  43.    int      count, i, j,
  44.             il1, ie1, ll1, le1,
  45.             il2, ie2, ll2, le2,
  46.             il3, ie3, ll3, le3,
  47.             length, lw,
  48.             value, width;
  49.    struct   tiff_header_struct image_header;
  50.  
  51.    my_clear_text_screen();
  52.  
  53.        /*********************************************
  54.        *
  55.        *   Interpret the command line parameters.
  56.        *
  57.        **********************************************/
  58.  
  59.    if(argc < 5){
  60.     printf(
  61.     "\n\nNot enough parameters:"
  62.      "\n"
  63.      "\n usage: boolean in-file1 in-file2 out-file "
  64.      "type [value] [il ie]"
  65.      "\n           or "
  66.      "\n        boolean in-file1 out-file not value"
  67.      "\n"
  68.      "\n recall type: and or xor nand nor not"
  69.      "\n              You must specify a value for "
  70.      "nand & nor"
  71.      "\n"
  72.      "\n If in-file1 is only one ROWSxCOLS in size,"
  73.      "\n then specify il ie for in-file2"
  74.      "\n");
  75.     exit(0);
  76.    }
  77.  
  78.    if(strcmp("not", argv[3]) == 0){
  79.       strcpy(name,  argv[1]);
  80.       strcpy(name2, argv[2]);
  81.       strcpy(type,  argv[3]);
  82.       value =  atoi(argv[4]);
  83.    }  /* ends if not */
  84.    else{
  85.       strcpy(name,  argv[1]);
  86.       strcpy(name2, argv[2]);
  87.       strcpy(name3, argv[3]);
  88.       strcpy(type,  argv[4]);
  89.       value =  atoi(argv[5]);
  90.    }  /* ends else all other types */
  91.  
  92.    il1 = 1;
  93.    ie1 = 1;
  94.    ll1 = ROWS+1;
  95.    le1 = COLS+1;
  96.  
  97.    il2 = 1;
  98.    ie2 = 1;
  99.    ll2 = ROWS+1;
  100.    le2 = COLS+1;
  101.  
  102.    il3 = 1;
  103.    ie3 = 1;
  104.    ll3 = ROWS+1;
  105.    le3 = COLS+1;
  106.  
  107.        /*********************************************
  108.        *
  109.        *   Read the input image header and setup
  110.        *   the looping counters.
  111.        *
  112.        **********************************************/
  113.  
  114.    read_tiff_header(name, &image_header);
  115.  
  116.    length = (ROWS-10 + image_header.image_length)/ROWS;
  117.    width  = (COLS-10 + image_header.image_width)/COLS;
  118.    count  = 1;
  119.    lw     = length*width;
  120.    printf("\nlength=%d  width=%d", length, width);
  121.  
  122.    if(length == 1   &&   
  123.       width  == 1   &&
  124.       strcmp("not", argv[3] != 0)){
  125.          il2 = atoi(argv[5]);
  126.          ie2 = atoi(argv[6]);
  127.          il3 = il2;
  128.          ie3 = ie2;
  129.          ll2 = il2+ROWS;
  130.          le2 = ie2+COLS;
  131.          ll3 = il3+ROWS;
  132.          le3 = ie3+COLS;
  133.    }  /* ends if length == width == 1 */
  134.  
  135.    if(length == 1   &&   
  136.       width  == 1   &&
  137.       strcmp("nand", argv[4] == 0)){
  138.          il2 = atoi(argv[6]);
  139.          ie2 = atoi(argv[7]);
  140.          il3 = il2;
  141.          ie3 = ie2;
  142.          ll2 = il2+ROWS;
  143.          le2 = ie2+COLS;
  144.          ll3 = il3+ROWS;
  145.          le3 = ie3+COLS;
  146.    }  /* ends if length == width == 1 */
  147.  
  148.    if(length == 1   &&   
  149.       width  == 1   &&
  150.       strcmp("nor", argv[4] == 0)){
  151.          il2 = atoi(argv[6]);
  152.          ie2 = atoi(argv[7]);
  153.          il3 = il2;
  154.          ie3 = ie2;
  155.          ll2 = il2+ROWS;
  156.          le2 = ie2+COLS;
  157.          ll3 = il3+ROWS;
  158.          le3 = ie3+COLS;
  159.    }  /* ends if length == width == 1 */
  160.  
  161.        /*********************************************
  162.        *
  163.        *   Loop over the input images and
  164.        *   apply the desired Boolean operator.
  165.        *
  166.        **********************************************/
  167.  
  168.    for(i=0; i<length; i++){
  169.       for(j=0; j<width; j++){
  170.          printf("\nrunning %d of %d", count, lw);
  171.          count++;
  172.  
  173.             /* AND */
  174.          if(strcmp("and", type) == 0){
  175.             and_image(name, name2, name3,
  176.                       the_image, out_image,
  177.                       il1+i*ROWS, ie1+j*COLS,
  178.                       ll1+i*ROWS, le1+j*COLS,
  179.                       il2+i*ROWS, ie2+j*COLS,
  180.                       ll2+i*ROWS, le2+j*COLS,
  181.                       il3+i*ROWS, ie3+j*COLS,
  182.                       ll3+i*ROWS, le3+j*COLS);
  183.          }  /* ends AND operation */
  184.  
  185.             /* OR */
  186.          if(strcmp("or", type) == 0){
  187.             or_image(name, name2, name3,
  188.                      the_image, out_image,
  189.                      il1+i*ROWS, ie1+j*COLS,
  190.                      ll1+i*ROWS, le1+j*COLS,
  191.                      il2+i*ROWS, ie2+j*COLS,
  192.                      ll2+i*ROWS, le2+j*COLS,
  193.                      il3+i*ROWS, ie3+j*COLS,
  194.                      ll3+i*ROWS, le3+j*COLS);
  195.          }  /* ends OR operation */
  196.  
  197.             /* XOR */
  198.          if(strcmp("xor", type) == 0){
  199.             xor_image(name, name2, name3,
  200.                       the_image, out_image,
  201.                       il1+i*ROWS, ie1+j*COLS,
  202.                       ll1+i*ROWS, le1+j*COLS,
  203.                       il2+i*ROWS, ie2+j*COLS,
  204.                       ll2+i*ROWS, le2+j*COLS,
  205.                       il3+i*ROWS, ie3+j*COLS,
  206.                       ll3+i*ROWS, le3+j*COLS);
  207.          }  /* ends XOR operation */
  208.  
  209.             /* NAND */
  210.          if(strcmp("nand", type) == 0){
  211.             nand_image(name, name2, name3,
  212.                        the_image, out_image,
  213.                        il1+i*ROWS, ie1+j*COLS,
  214.                        ll1+i*ROWS, le1+j*COLS,
  215.                        il2+i*ROWS, ie2+j*COLS,
  216.                        ll2+i*ROWS, le2+j*COLS,
  217.                        il3+i*ROWS, ie3+j*COLS,
  218.                        ll3+i*ROWS, le3+j*COLS,
  219.                        value);
  220.          }  /* ends NAND operation */
  221.  
  222.             /* NOR */
  223.          if(strcmp("nor", type) == 0){
  224.             nor_image(name, name2, name3,
  225.                       the_image, out_image,
  226.                       il1+i*ROWS, ie1+j*COLS,
  227.                       ll1+i*ROWS, le1+j*COLS,
  228.                       il2+i*ROWS, ie2+j*COLS,
  229.                       ll2+i*ROWS, le2+j*COLS,
  230.                       il3+i*ROWS, ie3+j*COLS,
  231.                       ll3+i*ROWS, le3+j*COLS,
  232.                       value);
  233.          }  /* ends NOR operation */
  234.  
  235.             /* NOT */
  236.          if(strcmp("not", type) == 0){
  237.             not_image(name, name2,
  238.                       the_image, out_image,
  239.                       il1+i*ROWS, ie1+j*COLS,
  240.                       ll1+i*ROWS, le1+j*COLS, value);
  241.          }  /* ends NOT operation */
  242.  
  243.       }  /* ends loop over j */
  244.    }  /* ends loop over i */
  245. }  /* ends main  */
  246.